@extends('admin.app')

@section('breadcrumb')
    <div class="bg-light lter b-b wrapper-md">
        <ol class="breadcrumb bg-light lter m-n no-padder">
            <li><a href="{{ admin_action('HomeController@index') }}">主页</a></li>
            <li>网站管理</li>
            <li class="active">文章管理</li>
        </ol>
    </div>
@endsection

@section('content')
    <div class="panel panel-default">
        <div class="panel-heading font-bold">
            文章列表
        </div>
        <div class="row wrapper">
            <div class="col-sm-8">
                <form class="form-horizontal" method="get"
                      action="{{ admin_action('Web\ArticlesController@index') }}">
                    <div class="row">
                        <div class="col-sm-5">
                            <div class="form-group">
                                <label class="control-label col-sm-4">文章标题:</label>
                                <div class="col-sm-8">
                                    <input class="form-control" type="text" placeholder="请输入文章标题" name="title"
                                           value="{{ $query['title'] }}"/>
                                </div>
                            </div>
                        </div>

                        <div class="col-sm-5">
                            <div class="form-group">
                                <label class="control-label col-sm-4">文章类型:</label>
                                <div class="col-sm-8">
                                    <select name="article_category_id" class="form-control select2">
                                        <option value="xx">----请选择文章类型----</option>
                                        @foreach( $article_categories as $article_category)
                                            @if($article_category->id == $query['article_category_id'])
                                                <option value="{{ $article_category->id }}"
                                                        selected="selected">{{ $article_category->name }}</option>
                                            @else
                                                <option value="{{ $article_category->id }}">{{ $article_category->name }}</option>
                                            @endif
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-1 text-left">
            <span class="input-group-btn">
              <button class="btn btn-sm btn-default" type="submit">查询</button>
            </span>
                        </div>
                    </div>
                </form>
            </div>
            <div class="col-sm-4 text-right text-center-xs">
                @accredit('web.navigations.create')
                <a class="btn m-b-xs btn-sm btn-default btn-addon"
                   href="{{ admin_action('Web\ArticlesController@create') }}">
                    <i class="fa fa-plus"></i>新增一篇文章
                </a>
                @endaccredit
            </div>
        </div>
        <div class="table-responsive">
            <table class="table table-striped b-t b-light">
                <thead>
                <tr>
                    <th>编号</th>
                    <th>标题</th>
                    <th>是否显示</th>
                    <th>发布时间</th>
                    <th>文章分类</th>
                    <th>是否推荐</th>
                    <th>文章类型</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @forelse ($articles as $article)
                    <tr>
                        <td>{{ $article->id }}</td>
                        <td>{{ $article->title }}</td>
                        <td>{{ $article->display==0?'否':'是' }}</td>
                        <td>{{ $article->published_at }}</td>
                        <td>{{ $article->category_name??' 无 ' }}</td>
                        <td>{{ $article->recommended==0?"否":"是" }}</td>
                        <td>{{ $article->article_type==0?"文章":"页面" }}</td>
                        <td>
                            <a class="btn btn-xs btn-primary"
                               href="{{ admin_action('Web\ArticlesController@show', [$article]) }}"
                               target="_blank" 
                               data-toggle="tooltip" title="预览该文章">
                                <i class="fa fa-info"></i>
                            </a>
                            <a class="btn btn-xs btn-primary"
                               href="{{ admin_action('Web\ArticlesController@edit', [$article]) }}"
                               data-toggle="tooltip" title="编辑该文章">
                                <i class="fa fa-pencil"></i>
                            </a>
                            <form class="inline"
                                  action="{{ admin_action('Web\ArticlesController@destroy', [$article]) }}"
                                  method="post">
                                {{ csrf_field() }}
                                {{ method_field('DELETE') }}
                                <button type="button" data-swal-role="delete-confirm" data-swal-title="温馨提示"
                                        data-swal-text="您将删除文章 <{{ $article->title }}>   "
                                        class="btn btn-xs btn-danger" data-toggle="tooltip" title="删除文章">
                                    <i class="fa fa-trash-o"></i>
                                </button>
                            </form>
                        </td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="3" class="text-center">没有找到文章记录</td>
                    </tr>
                @endforelse
                </tbody>
            </table>
        </div>
        <div class="panel-footer">
            <div class="row">
                <div class="col-sm-12 text-right text-center-xs">
                    {!! $links !!}
                </div>
            </div>
        </div>
    </div>
@endsection